package kr.hkit.androidcomplete01.chapter09;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;

public class PopupMenuEx extends Activity {
	Button mBtn;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch09_popupmenuex);
		mBtn = (Button) findViewById(R.id.ch09_popupmenu_btn);
	}
	
	public void mOnClick(View v){
		PopupMenu popup = new PopupMenu(this, v);
		MenuInflater inflater = popup.getMenuInflater();
		Menu menu = popup.getMenu();
		inflater.inflate(R.menu.popupmenu, menu);
		
		popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			public boolean onMenuItemClick(MenuItem item) {
				switch(item.getItemId()){
				case R.id.popup_red:
					mBtn.setBackgroundColor(Color.RED);
					break;
				case R.id.popup_green:
					mBtn.setBackgroundColor(Color.GREEN);
					break;
				case R.id.popup_blue:
					mBtn.setBackgroundColor(Color.BLUE);
					break;
				case R.id.popup_black:
					mBtn.setTextColor(Color.BLACK);
					break;
				case R.id.popup_white:
					mBtn.setTextColor(Color.WHITE);
					break;
				case R.id.popup_gray:
					mBtn.setTextColor(Color.GRAY);
					break;
				}
				return false;
			}
		});
		
		popup.show();
	}
}
